package com.besttone.model;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.besttone.common.StaticConstantType;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;

@SuppressWarnings("serial")
public class HSmsDispatch extends Model<HSmsDispatch> {
    private static Log _log = LogFactory.getLog(HSmsDispatch.class);
    public static HSmsDispatch dao = new HSmsDispatch();

    /**
     * 查询未同步的数据
     * 
     * @return
     */
    public List<HSmsDispatch> getNotSyncData_old() {
	StringBuffer buf = new StringBuffer();
	buf.append(" select h.ID as id,h.MSGID as msg_id,h.MSGCONTENT as msg_content,h.TARGET_NUMBER as target_number,h.SEND_NUMBER as send_number,h.TOTAL as total,");
	buf.append(" h.CALL_STATUS as call_status,h.SEND_TIME as send_time,h.RECEIVE_TIME as reveive_time,n.mttype as mt_type,n.mtstatus as mt_status,n.mterrcode as mt_errcode");
	buf.append(" from notifymesage n,H_SMS_DISPATCH h where ");
	buf.append(" h.IS_SYNC=");
	buf.append(StaticConstantType.IS_NOT_SYNC);
	buf.append(" and n.mtmsgid=h.MSGID");
	_log.info("查询:" + buf.toString());
	return dao.find(buf.toString());
    }

    public Page<HSmsDispatch> getNotSyncData(int pageNumber) {
	// StringBuffer buf = new StringBuffer();
	String select = "select h.ID as id,h.template_code as template_code,h.MSGID as msg_id,h.MSGCONTENT as msg_content,h.TARGET_NUMBER as target_number,h.SEND_NUMBER as send_number,h.TOTAL as total,h.CALL_STATUS as call_status,h.SEND_TIME as send_time ";
	// buf.append("select h.ID as id,h.MSGID as msg_id,h.MSGCONTENT as msg_content,h.TARGET_NUMBER as target_number,h.SEND_NUMBER as send_number,h.TOTAL as total,h.CALL_STATUS as call_status,h.SEND_TIME as send_time ");
	// buf.append(" from h_sms_dispatch h where IS_SYNC=");
	String sqlExceptSelect = " from H_SMS_DISPATCH h where " + "IS_SYNC="
		+ StaticConstantType.IS_NOT_SYNC + "  order by SEND_TIME desc";
	// buf.append(StaticConstantType.IS_NOT_SYNC);
	// _log.info("查询:" + buf.toString());
	return dao.use("hooksms").paginate(pageNumber, 10, select,
		sqlExceptSelect);
    }
}
